///////////////////////////////////////////////////////////////////////////////

#ifndef _CLIENTBATTLEFIELD_H_
#define _CLIENTBATTLEFIELD_H_

////////////////////////////////////////////////////////////////////////////////

#ifndef _BATTLEFIELD_H_
#include "battlefield.h"
#endif

////////////////////////////////////////////////////////////////////////////////

class ServerState;
class IGameObjectIterator;
class IGameObjectConstIterator;

////////////////////////////////////////////////////////////////////////////////


/** Battlefield representation on client side.
*
*  @author   Anastasia Karpinska
*  @since    Nov 12th, 2009
*  @updated  Dec 04th, 2009
*/
class ClientBattlefield : public Battlefield
{
////////////////////////////////////////////////////////////////////////////////

public:

////////////////////////////////////////////////////////////////////////////////


    /** Constructor */
    ClientBattlefield();


    /** Integrate two server states and put the result into battlefield */
    void Integrate( const ServerState& _firstState,
                    const ServerState& _secondState,
                    double _firstToSecondCoeff );


    /** Returns health points of given player */
    int GetHealthPoints( int _playerID );

    bool PlayersAdded();
    bool PlayersDeleted();
    bool BulletsAdded();
    bool BulletsDeleted();

////////////////////////////////////////////////////////////////////////////////

private:

////////////////////////////////////////////////////////////////////////////////
    bool m_PlayersAdded;
    bool m_PlayersDeleted;
    bool m_BulletsAdded;
    bool m_BulletsDeleted;

    /** Integrate objects in two server states
    and put the result into current battlefield objects */
    template <typename _CollType>
    int IntegratePositions( _CollType& _currStateObjects,
                             const _CollType& _firstStateObjects,
                             const _CollType& _secondStateObjects,
                             double _firstToSecondCoeff );


    /** Synchronizes first and current state objects.
    Checks for all new objects in the first state
    and puts them to current state.
    Checks for all deleted objects in first state
    and removes them from current state. */
    template <typename _CollType>
    void SynchronizeFirstAndCurrentState( _CollType& _currStateObjects,
                                          const _CollType& _firstStateObjects );


    /** Integrates first and second objects and puts the result in current. */
    void IntegrateObjectPosition( GameObject& _current,
                                  const GameObject& _first,
                                  const GameObject& _second,
                                  double _firstToSecondCoeff );


    /** Updates health points according with the last state */
    void UpdateHealthPoints( PlayersList& _currStatePlayers,
                             const PlayersList& _firstStatePlayers );


////////////////////////////////////////////////////////////////////////////////
};

////////////////////////////////////////////////////////////////////////////////

#endif

////////////////////////////////////////////////////////////////////////////////
